package com.qiandw.controller;

import com.qiandw.entity.LeaveBill;
import com.qiandw.service.LeaveBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author KG
 */
@RestController
@RequestMapping("/leaveBill")
public class LeaveBillController {
    @Autowired
    private LeaveBillService leaveBillService;

    /**
     * 新增
     *
     * @param leaveBill 请假单
     * @return
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST, RequestMethod.GET})
    public Object add(LeaveBill leaveBill) {
        leaveBill.setId(UUID.randomUUID().toString());
        leaveBillService.add(leaveBill);
        return "新增请假单成功";
    }

    /**
     * 更具用户id查询代办项目
     *
     * @param userId 用户id
     * @return
     */
    @RequestMapping(value = "/findTaskByUserId", method = {RequestMethod.POST, RequestMethod.GET})
    public Object findTaskByUserId(String userId) {
        return leaveBillService.findByUserId(userId);
    }

    /**
     * 完成任务
     *
     * @param taskId 任务id
     * @param userId 用户id
     * @param audit  审批意见
     * @return
     */
    @RequestMapping(value = "/completeTaskByUser", method = {RequestMethod.POST, RequestMethod.GET})
    public Object completeTaskByUser(String taskId, String userId, String audit) {
        leaveBillService.completeTaskByUser(taskId, userId, audit);
        return "审批完成";
    }
}
